import SocketAPI from "@/api/socket/socket";
const controller = {
  data() {
    return {
      device: { name: null, code: null },
    };
  },
  mounted() {
    if (!device.code) {
      console.error("device code is empty");
      return;
    }
    this.bind();
  },
  destory() {
    this.unbind();
  },
  methods: {
    websocketReceive(json) {
      console.log(json);
    },
    websocketCommand(data) {
      SocketAPI.sendData(data);
    },
    bind() {
      SocketAPI.subscribe(this.device.code);
      SocketAPI.addHandle(this.websocketReceive);
    },
    unbind() {
      SocketAPI.unsubscribe(this.device.code);
      SocketAPI.removeHandle(this.websocketReceive);
    },
  },
};

export default controller;
